﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using Moonwish.Core;
using Moonwish.Core.DataAccess;
using Moonwish.Core.EntityCore;
using Moonwish.SchoolDorms.DataEntity;

namespace Moonwish.SchoolDorms.DataAccess.SqlServer.BuildCmd
{
    public class AddCommand : EntityCommand<V_SCD_Build>
    {
        public AddCommand(DbContext dbContext, List<V_SCD_Build> items, string userId)
            : base(dbContext, items, userId)
        {
        }

        public override void Execute()
        {
            var buildSet = DbContext.Set<T_SCD_Build>();
            foreach (var item in Items)
            {
                var newBuild = new T_SCD_Build
                {
                    Build_Id = item.Build_Id,
                    Name = item.Name,
                    Floors = item.Floors,
                    DutyMan = item.DutyMan,
                    DutyTel = item.DutyTel
                };
                buildSet.Add(newBuild);
            }
            DbContext.SaveChanges();
        }
    }
}
